package com.haole.ecommercepay.balance.service.impl;

import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.haole.ecommercepay.balance.entity.QueryBalanceParam;
import com.haole.ecommercepay.balance.service.BalanceService;
import com.haole.ecommercepay.balance.url.BalanceUrl;
import com.haole.ecommercepay.common.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author haole
 */
@Service("balanceService")
public class BalanceServiceImpl implements BalanceService {

    private static final Logger logger = LoggerFactory.getLogger(BalanceServiceImpl.class);

    /**
     * 查询二级商户账户实时余额
     * @param param
     * @return
     */
    @Override
    public JSONObject subBlance(QueryBalanceParam param) {
        logger.info("subBlance param:{}",param);
        HttpResponse response = HttpUtils.v3HttpExecute("GET", String.format(BalanceUrl.SUB_BALANCE,param.getSub_mchid()),
                param.getAppName(),param.getMchId(),param.getMchSerialNo(),
                param.getWechatSerialNo(),"",param.getMchPrivateKeyPath(),null);
        logger.info("subBlance result:{}",response);
        return HttpUtils.httpResult(response,param.getWechatPubKeyPath());
    }
}
